<template>
  <div class="myContainer">
    <el-row class="myBorderBottom myMarginBottom_10px">
      <el-col :span="7" class="myTitleText">基本信息</el-col>
    </el-row>

    <el-row :gutter="10" class="myMarginBottom_10px">
      <el-col :span="3" class="myLeftMsg">
        <span class="require myVA_M">*</span>
        考核类型代码 :
      </el-col>
      <el-col :span="6">
        <el-input placeholder="考核类型代码" v-model="type_no" :readonly="readonly"></el-input>
      </el-col>
    </el-row>

    <el-row :gutter="10" class="myMarginBottom_10px">
      <el-col :span="3" class="myLeftMsg">
        <span class="require myVA_M">*</span>
        考核类型名称 :
      </el-col>
      <el-col :span="6">
        <el-input placeholder="考核类型名称" v-model="type_name" :readonly="readonly"></el-input>
      </el-col>
    </el-row>

    <el-row :gutter="10" class="myMarginBottom_10px">
      <el-col :span="3" class="myLeftMsg">
        <span class="require myVA_M">*</span>
        考核类型总分值 :
      </el-col>
      <el-col :span="6">
        <el-input placeholder="考核类型总分值" v-model="type_score" :readonly="readonly"></el-input>
      </el-col>
    </el-row>
    
    <el-row class="myBorderBottom myMarginBottom_10px">
      <el-col :span="7" class="myTitleText">状态及备注</el-col>
    </el-row>

    <el-row :gutter="10" class="myMarginBottom_10px">
      <el-col :span="3" class="myLeftMsg">
        <span class="require myVA_M">*</span>
        启用状态 :
      </el-col>
      <el-col :span="6" class="myLineHeight_40px">
        <template>
          <el-radio-group v-model="status">
            <el-radio :label="1">启用</el-radio>
            <el-radio :label="0">禁用</el-radio>
          </el-radio-group>
        </template>
      </el-col>
    </el-row>

    <el-row :gutter="10" class="myMarginBottom_10px">
      <el-col :span="3" class="myLeftMsg">
        备注 :
      </el-col>
      <el-col :span="6">
        <el-input placeholder="备注" type="textarea" v-model="type_note" :readonly="readonly"></el-input>
      </el-col>
    </el-row>

    <el-row :gutter="10" class="myMarginBottom_10px">
      <el-col :span="6" :offset="3">
        <el-button type="primary" v-if="type=='add'" @click="add">新增</el-button>
        <el-button type="primary" v-if="type=='update'" @click="update">保存</el-button>
        <el-button type="primary" @click="back">返回</el-button>
      </el-col>
    </el-row> 
  </div>
</template>     
  
<style scoped>
  .myBorderBottom{
    border-bottom:1px dotted #dbdbdb;
    padding-bottom: 5px;
  }
  .myTextAlignRight{
    text-align: right;
  }
  .myContainer{
    background: #fff;
    padding: 10px;
  }
  .myTitleText{
    font-weight: 500;
    font-size: 16px;
  }
  .myLineHeight_40px{
    line-height: 40px;
  }
  .myPaddingTop_10px{
    padding-top: 10px;
  }  
  .myred{
    color: #f00;
    font-size: 12px;
  }
  .myMarginBottom_10px{
    margin-bottom: 10px;
  }
  .myLeftMsg{
    line-height: 40px;
    text-align: right;
  }
  .myVA_M{
    vertical-align: middle;
  }
  .mymarginTop_10px{
    margin-top: 10px;
  }
  .myOV_y_400px{
    border:1px solid #f2f2f2;
    box-sizing: border-box;
    min-height: 200px;
    max-height: 400px;
    overflow-y: scroll; 
  } 
</style>

<script> 
  import { addType , updateType , infoType } from '@/api/quality';
  export default {
    data(){
      return{
        title:"考核类型详细",
        type:"",
        id:"",
        readonly:false,
        kw_role:"",
        newRoleDialogVisible:false,
        roleDlgList:[],
        roleLoading:false,
        roleIdList:"",
        roleNameList:"",
        roleDlgProps: {
          children: 'children',
          label: 'role_name'
        },
        type_no:"",
        type_name:"",
        type_score:"",
        status:1,
        type_note:""
      }
    },
    components: {
    },
    created(){
      this.type=this.$route.query.type;
      this.id=this.$route.query.id;
      if(this.type=="add"){
        document.title="新增考核专业";
      }else if(this.type=="info"){
        this.readonly=true;
        this.info();
      }else if(this.type=="update"){
        document.title="编辑考核专业"; 
        this.info();
      } 
    },
    computed: {
    },
    watch: { 
    },
    methods:{
      add(){
        let vm=this;
        let params={
          "type_no": vm.type_no,
          "type_name": vm.type_name,
          "type_score": vm.type_score,
          "status": vm.status,
          "type_note": vm.type_note
        }
        addType(params).then(response => {
          vm.$message.success("执行成功！");
          vm.back();
        }).catch(error => {
          vm.$message.error("执行失败！"+error.response.data.error_msg);
        })
      },
      update(){
        let vm=this;
        let params={
          "type_no": vm.type_no,
          "type_name": vm.type_name,
          "type_score": vm.type_score,
          "status": vm.status,
          "type_note": vm.type_note
        }
        updateType(params,vm.id).then(response => {
          vm.$message.success("执行成功！");
          vm.back();
        }).catch(error => {
          vm.$message.error("执行失败！"+error.response.data.error_msg);
        })
      },
      back(){
        this.$router.go(-1);
      },
      info(){
        let vm=this;
        infoType(vm.id).then(response => {
          let res=response.data;
          vm.type_no=res.type_no;
          vm.type_name=res.type_name;
          vm.type_score=res.type_score;
          vm.status=res.status;
          vm.type_note=res.type_note;
        }).catch(error => {
          vm.$message.error("执行失败！"+error.response.data.error_msg);
        })
      } 
    }
}
</script>

